home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14028 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  53 lines

  1. Newsgroups: comp.lang.c
  2. Path: netcom.com!smryan
  3. From: smryan@netcom.com (@#$%!?!)
  4. Subject: Re: ellipse parameter of printf()
  5. Message-ID: <smryanDpoLLF.IwJ@netcom.com>
  6. Organization: The Programmer formerly known as S M Ryan
  7. X-Newsreader: TIN [version 1.2 PL1]
  8. References: <4kh5p8$lm4@dewey.csun.edu>
  9. Date: Thu, 11 Apr 1996 04:53:39 GMT
  10. Sender: smryan@netcom3.netcom.com
  11.  
  12. :     In stdio.h,the parameter printf() is '...',what is that means,
  13. : how compiler treat this ?
  14.  
  15. In a function declaration, '...' means 'and an indefinite number of
  16. additional parameters.'
  17.  
  18.     printf(char*,...)
  19.  
  20. takes a char* and an indefinite number of additional parameters.
  21.  
  22.     fprintf(FILE*,char*,...)
  23.  
  24. takes a FILE*, a char*, and an indefinite number of additional parameters.
  25.  
  26.  
  27. The additional parameters are called varargs, from <varargs.h>, the old
  28. way for a function (like printf) to access those additional parameters.
  29. The ANS-C method uses <stdarg.h>.
  30.  
  31. With varargs, the compiler has no types to check the actual parameters
  32. to, nor does the language definition provide any mechanism to pass the
  33. actual number and types of parameter. The called function must use
  34. earlier entries in the parameter list or some other technique to decide
  35. how many parameters are present and what their types are. The caller 
  36. must obey the calling conventions--there is in general no standard way
  37. for the compiler to enforce such conventions.
  38.  
  39. In particular, printf assumes the number and types of parameters based
  40. on the format specifications in the first first parameter. In
  41.  
  42.     printf("%s-%d-%f\n",
  43.  
  44. printf will assume it has three additional parameters, the first being
  45. char*, the second int, the third double. (Float and short parameters are
  46. automatically converted to doubles and ints by the compiler.)
  47.  
  48. -- 
  49. The Queen, amused, in quiet power,         | smryan@netcom.com  PO Box 1563
  50. will draw the son to darkenned bower.      |          Cupertino, California
  51. Her face is fair, her fragrance rare,      | (xxx)xxx-xxxx            95015
  52. with woven webs for wayward flower.        |         I don't use no smileys
  53.